package com.hdax.dm.listener;

import com.hdax.dm.feign.SeatFeign;
import com.hdax.dm.service.OrderLinkUserService;
import com.hdax.dm.service.OrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@RabbitListener(queues = "dm_order_dlx_queue")
@Component
public class TimeoutRabbitListener {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderLinkUserService orderLinkUserService;

    @Autowired
    private SeatFeign seatFeign;

    @RabbitHandler
    public void rabbitHandler(String orderNo){
        if (orderService.orderOne(orderNo).getOrderType()!=2L){
            System.out.println("订单："+orderNo+"已超时");

            Boolean isSeat=seatFeign.ishaveSeatUpdate(1L,orderNo);
            orderService.orderUpdate(-1L,orderNo);
            orderLinkUserService.orderLinkUserDel(orderNo);
            if (!isSeat){
                System.out.println("修改失败");
            }
        }
    }
}
